package cn.tedu._07springaop.egaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggerAspect {
    @Pointcut("execution(public boolean cn.tedu._07springaop.egaop.CartServiceImpl.*(..))")
    public void doTime() {
    }
    @Around(value = "doTime()")
    public Object aroundMethod(ProceedingJoinPoint joinPoint) {
        Object cartDetail = null;
        try {
            System.out.println("环绕通知：前置通知：开始添加购物车");
            cartDetail = joinPoint.proceed();
            System.out.println("环绕通知：返回通知：添加购物车成功");
        } catch (Throwable e) {
            System.out.println("环绕通知：异常通知：添加购物车失败");
            throw new RuntimeException(e);
        } finally {
            System.out.println("环绕通知：后置通知：操作完成");
        }
        return cartDetail;
    }
}
